import java.util.ArrayList;
import java.util.List;

import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiMessage;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Receiver;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import javax.sound.midi.ShortMessage;
import javax.sound.midi.Track;
import javax.sound.midi.Transmitter;
import javax.sound.midi.MidiDevice.Info;

import midi.MidiPhrase;

public class MidiTest2 {

	public static void main(String args[]){
		try{
		int i = 0;
		
		Info[] info = MidiSystem.getMidiDeviceInfo();
		for (i = 0; i < info.length; i++){
			
			System.out.println(info[i]);
			/*
			if (info[i].toString().contains("Loop"))
			{
				break;
			}
			*/
		}
		
		System.out.println(info[3].getName());
		System.out.println(info[3].getDescription());
		
		MidiDevice loopBe = MidiSystem.getMidiDevice(info[3]);
		
		System.out.println(loopBe.getMaxReceivers());
		
		loopBe.open();
		Receiver rec = loopBe.getReceiver();
		
		ShortMessage msg = new ShortMessage();
		msg.setMessage(ShortMessage.NOTE_ON, 1, 72, 90);
		
		//rec.send(msg, 0);
		
		ShortMessage msg2 = new ShortMessage();
		msg2.setMessage(ShortMessage.NOTE_ON, 2, 60, 90);
		
		rec.send(msg2, 0);
		
		Thread.sleep(1000);
		
		ShortMessage endMsg = new ShortMessage();
		endMsg.setMessage(ShortMessage.NOTE_OFF, 1, 72, 0);
		
		ShortMessage endMsg2 = new ShortMessage();
		endMsg2.setMessage(ShortMessage.NOTE_OFF, 2, 60, 90);
		
		rec.send(endMsg, 0);
		rec.send(endMsg2, 0);
		
		Thread.sleep(5);
		
		rec.close();
		}
		catch (Exception e)
		{
		}
	}

}


	
